﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ABELGX
{
    /// <summary>
    /// UserControlIconValue.xaml 的交互逻辑
    /// </summary>
    public partial class UserControlIconValue : UserControl
    {
        #region Value
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(string), typeof(UserControlIconValue),
               new PropertyMetadata((string)null, new PropertyChangedCallback(ValueChanged)));

        private static void ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as UserControlIconValue;
            if (control != null)
            {
                string oldValue = e.OldValue as string;  // 旧的值
                string newValue = e.NewValue as string; // 更新的新的值
                if (oldValue != newValue)
                {
                    control.UpdateValue(newValue);
                }
            }
        }
        private void UpdateValue(string newValue)
        {
            LabelValue.Content = newValue;
        }

        [Bindable(true)]
        [Category("Appearance")] // using System.ComponentModel;
        public string Value
        {
            get
            {
                return (string)GetValue(ValueProperty);
            }
            set
            {
                SetValue(ValueProperty, value);
            }
        }
        #endregion

        public ImageSource Source
        {
            get => ImageIcon.Source;
            set => ImageIcon.Source = value;
        }
        public event EventHandler Click;
        public UserControlIconValue()
        {
            InitializeComponent();
            ImageIcon.MouseUp += ImageIcon_MouseUp;
            ImageIcon.TouchUp += ImageIcon_TouchUp;
        }

        private void ImageIcon_TouchUp(object sender, TouchEventArgs e)
        {
            if(Click != null)
            {
                Click(this, e);
            }
        }

        private void ImageIcon_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }
    }
}
